/**
 * 随堂检测
 */
var localStorageManagers = require("script/localStorageManagers.js");
var mobileFrame = require('scripts/Core/MobileFrame.js');
//mui初始化
mui.init({
	swipeBack: true
});
//plus初始化
mui.plusReady(function() {
	plusReady();
});
//plusReady
function plusReady() {
	//滚动条
	mui('.mui-scroll-wrapper').scroll({
					indicators: false //是否显示滚动条
				});
	//加载随堂jiance
	loadNoteDiv();
	//切换课程笔记
	mui('#courselitop').on('tap', '.courseli', clickcourseli);
	//打开课题对应的笔记列表
	mui('.coursediv').on('tap', '.catalogdiv', openNotelist);
	//返回主页面
	mui('header').on('tap','#backindex1',backIndex);
};
//加载笔记列表
function loadNoteDiv() {
	document.getElementById('coursediv').innerHTML=' ';
	if(mobileFrame.IsNetWorkCanUse()){
		document.getElementById('nettip').style.display='none';
	    ajaxLoadNote();
	}else{
		document.getElementById('nettip').style.display='block';
	}
}
//ajax加载笔记列表
function ajaxLoadNote() {
	var userid = localStorageManagers.getUseridSession();
	var url = serverAjax + "/mobile/classroomtest/getClassRoomTestList.do";
	var w=plus.nativeUI.showWaiting();
	mui.ajax(url, {
		data: {
			userid: userid
		},
		type: 'post',
		dataType: 'json',
		timeout: 10000,
		success: function(data) {
			
			if (data == null){ 
				w.close();
				return;
			}
			buildNoteDiv(data);
            w.close();			
		},
		error: function(e1, e2, e3) {
			ajaxErrorTip();
			w.close();
			console.log(e1);
		}
	});
};
//buildNoteDiv
function buildNoteDiv(data) {
	for (var i = 0; i < data.length; i++) {
		var courselitop = document.getElementById('courselitop');
		var courseli = document.getElementById('courseli_' + data[i].courseId);
		//头部列表
		var act = '';
		if (i == 0) act = 'act';
		if (courseli == null) courselitop.innerHTML = courselitop.innerHTML + '<span class="courseli c1 ' + act + '" id="courseli_' + data[i].courseId + '" courseid="' + data[i].courseId + '">' + data[i].courseName + '</span>';
		//中间列表
		var coursediv = document.getElementById('coursediv');
		var catalogsdiv = document.getElementById('catalogsdiv_' + data[i].courseId);
		if (catalogsdiv == null) {
			coursediv.innerHTML = coursediv.innerHTML + '<div class="catalogsdiv ' + act + '" id="catalogsdiv_' + data[i].courseId + '"></div>';
			catalogsdiv = document.getElementById('catalogsdiv_' + data[i].courseId);
		}
		var isNone = 'none';
		var isreport = 0;
		if (data[i].daanNum > 0) {
			isNone = '';
			isreport = 1;
		}
		var catalogstr = '<div class="catalogdiv" catalogid="' + data[i].catalogId + '" catalogname="' + data[i].catalogName + '" resid="' + data[i].resId + '" resname="' + data[i].title + '" isreport="' + isreport + '">' + '<div class="r1"><img src="../../images/note_1.png"><span class="c1">' + data[i].courseName + '</span></div>' + '<div class="r2"><span class="c1">课题：' + data[i].catalogName + '</span><span class="navigate-right"></span><span class="suborres ' + isNone + '"><img src="../../images/test_1.png"><span></div>' + '<div class="r3"><img src="../../images/note_6.png"><span class="c1">测试题：' + data[i].timuNum + '</span></div>' + '</div>';
		catalogsdiv.innerHTML = catalogsdiv.innerHTML + catalogstr;
	}
}
//切换课程
function clickcourseli() {
	
	var courselis = document.getElementsByClassName('courseli');
	for (var i = 0; i < courselis.length; i++) {
		courselis[i].className = 'courseli c1';
	}
	this.className = 'courseli c1 act';

	var items = document.getElementsByClassName('catalogsdiv');
	for (var i = 0; i < items.length; i++) {
		items[i].className = 'catalogsdiv';
	}

	var courseid = this.getAttribute('courseid');
	var catalogsdiv = document.getElementById('catalogsdiv_' + courseid);
	catalogsdiv.className = 'catalogsdiv act';
}
//打开笔记列表页面
function openNotelist() {
	var catalogid = this.getAttribute('catalogid');
	var catalogname = this.getAttribute('catalogname');
	var resid = this.getAttribute('resid');
	var resname = this.getAttribute('resname');
	var isreport = this.getAttribute('isreport');
	var data = {
		catalogid: catalogid,
		catalogname: catalogname,
		resid: resid,
		resname: resname
	};
	if (isreport == 0) {
		mui.openWindow({
			url: 'testlist.html',
			id: 'selfcenter/classroomtest/testlist'+resid,
			extras: data
		});
	} else {
		mui.openWindow({
			url: 'testreport.html',
			id: 'selfcenter/classroomtest/testreport'+resid,
			extras: data
		});
	}
};
//mui.back=function(){
	//mui.openWindow({
//		url:'../../index.html',
	//	id:'index.html',
   // waiting:{
    //  autoShow:false//自动显示等待框，默认为true
    //},
   // extras:{activeid:2}
	//});
//	mui.back();
//}
//返回主页面
function backIndex(){
}
